// 测试 Array 的类方法

let first = Array.of();
console.log( first, first.length );
console.log( Array.isArray( first ) );

let second = Array.of(10);
console.log( second, second.length );
console.log( Array.isArray( second ) );

let third = Array.of(10,15,20);
console.log( third, third.length );
console.log( Array.isArray( third ) );

let like = {
    "name": '类数组对象',
    "0": 100,
    "1": 200,
    "2": 300,
    "3": 400,
    "length": 4,
    "item": function(index){
        return this[index];
    }
}

console.log( like );
console.log( '用普通for循环遍历类数组对象' );
for( let i = 0 ; i < like.length; i++ ){
    let value = like[i];
    console.log( '\t', value );
}
console.log( 'like is array: ' , Array.isArray( like )); // false

// 将 类数组对象 转换为 数组
let arr = Array.from( like );
console.log( 'arr is array: ' , Array.isArray( arr ) ); // true
for( let i = 0 ; i < arr.length; i++ ){
    let value = arr[i];
    console.log( '\t', value );
}

// 总结:
// Array.of([...elements]) 返回包含了指定原始的新数组对象
// Array.isArray( target ) 判断参数对应的实例是否是数组
// Array.from( like ) 将参数对应的"类数组对象(即实例)"转换为数组

// 参考文档:
// https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array